var initData = function(num){
    var param = {
            page_num:num,
            page_size:"10"
        }
        $.ajax({
            url: base + "/dataCenter/businessdata/findzzMileageLibrary",
            data: param,
            success: function (data, textStatus, jqXHR) {
                if(data.list != null){
                    var pageCount = data.pager.pageCount;
                    var dataObj ={
                        "list":data.list,
                        "dataTool":{
                            "title":{
                            	"serial_number":"序号"
                                ,"origin":"起点"
                                ,"arrival":"迄点"
                                ,"mileage":"里程"
                                ,"operation":"操作"
                            },
                            "titleCheckbox":false,
                            "btn":[{"event":"deleteObj","name":"删除"}]
                        }
                    };
                    showPageTable('view', dataObj,num,pageCount,"initData");
                }
            },
            error: function () {
            }
        });
}

var deleteObj = function(obj){
	var id = obj.id;
    layer.confirm('确认删除?',{btn : [ '确定', '取消' ]},function(index){
	   layer.close(index);
	   $.ajax({
		   url:base+"/dataCenter/businessdata/delzzMileageLibrary/"+id,
		   data:{},
		   success:function(data,status){
			    if(data.statusCode == 0){
					layer.msg(data.message, {
						icon : 1
					});
			    }else{
					layer.msg(data.message, {
						icon : 5
					});
			    }
			    initData(1);
		   }
	   });
    });
}

//添加车站里程数据库
var addZzMileage = function(){
    var contentDiv = function(){
        var content;
        var data={
            "title":{
                "serial_number":"序号",
                "origin":"起点",
                "arrival":"迄点",
                "mileage":"里程"
            },"text":{
                "serial_number":"",
                "origin":"",
                "arrival":"",
                "mileage":""
            },"input":{
                "serial_number":"text",
                "origin":"text",
                "arrival":"text",
                "mileage":"text"
            },"input_init":{
            }
        };
        var getDiv =  dc_update.innerHTML;
        laytpl(getDiv).render(data, function(html){
            content = html;
        });
        return content;
    }
    layopen(contentDiv());
}

//打开弹窗
var layopen = function(content){
    layer.open({
        title:'更新站站里程数据库'
        ,content: content
        ,area: ['700px', '700px']
        ,scrollbar: false
        ,btn: ['确认', '取消']
        ,yes: function(index,layero){ //确认
            var data = $(layero).find("form").serializeJSON();
            $.post(base+"/dataCenter/businessdata/updatezzMileageLibrary",data,
                    function (data,status){
                        if(data!=""&&data!=null){
                            if(data.statusCode == 0){
                                layer.msg('更新成功', {icon: 1,time:2000});
                            }else{
                                layer.msg(data.message, {icon: 2,time:2000});
                            }
                        }else{
                            layer.msg('更新失败!', {icon: 2,time:2000});
                        }
                        initData(1);
                    })
        }
    });
}

$(document).ready(function(){
	initData(1);
});